package ar.edu.unicen.exa.isistan.archassis.rcs.svn;

import java.util.ArrayList;
import java.util.List;

import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNNodeKind;
import org.tmatesoft.svn.core.wc.ISVNDiffStatusHandler;
import org.tmatesoft.svn.core.wc.SVNDiffStatus;
import org.tmatesoft.svn.core.wc.SVNStatusType;

import ar.edu.unicen.exa.isistan.archassis.rcs.RCSFileDiff;
import ar.edu.unicen.exa.isistan.archassis.rcs.RCSFileModification;

public class SVNDiffList implements ISVNDiffStatusHandler {

	private List<RCSFileDiff> list = new ArrayList<RCSFileDiff>();
	
	@Override
	public void handleDiffStatus(SVNDiffStatus diffStatus) throws SVNException {
		
		RCSFileDiff fileDiff = new RCSFileDiff();
		
		fileDiff.setPath(diffStatus.getPath());
		
		fileDiff.setModificationType(translateStatus(diffStatus.getModificationType()));
		
		
		if (SVNNodeKind.FILE.equals(diffStatus.getKind())) {
			list.add(fileDiff);
		} else {
			System.out.println("Se omitio la modificacion " + diffStatus.getModificationType() + " sobre " + diffStatus.getKind() + " " + fileDiff.toString());
		}
		
	}
	private static RCSFileModification translateStatus(SVNStatusType s) {
		if (SVNStatusType.STATUS_DELETED.equals(s)) {
			return RCSFileModification.DELETED;
		} else if (SVNStatusType.STATUS_MODIFIED.equals(s)) {
			return RCSFileModification.MODIFIED;
		} else if (SVNStatusType.STATUS_ADDED.equals(s)) {
			return RCSFileModification.ADDED;
		} else {
			System.out.println("WARN: unused modification '" + s + "'");
			return RCSFileModification.NONE;
		}
	}

	public List<RCSFileDiff> toList() {
		return list;
	}

}
